package com.example.kick.designpattern;

import java.lang.ref.WeakReference;
import java.util.concurrent.*;

public class KickSingleton {

    private volatile static KickSingleton INSTANCE;

    private KickSingleton() {
    }

    public static KickSingleton getInstance() {
        if (null == INSTANCE) {
            synchronized (KickSingleton.class) {
                if (null == INSTANCE) {
                    INSTANCE = new KickSingleton();
                }
            }
        }
        return INSTANCE;
    }

    private static void testIdeaMainThreads() {
        ThreadGroup tg = Thread.currentThread().getThreadGroup();
        int tNo = tg.activeCount();
        Thread[] tThreads = new Thread[tNo];
        tg.enumerate(tThreads);
        for (int i = 0; i < tNo; i++) {
            System.out.println(i + ":" + tThreads[i].getName());
        }
    }

    static class KickThread implements Runnable {
        @Override
        public void run() {
            for (int i = 0; i < 20; i++) {
                System.out.println("T-zero serial: " + Thread.currentThread().getName());
            }
        }
    }

    static class KickThread1 implements Runnable {
        @Override
        public void run() {
            for (int i = 0; i < 20; i++) {
                System.out.println("T-one serial: " + Thread.currentThread().getName());
            }
        }
    }

    static class KickThread2 implements Runnable {
        @Override
        public void run() {
            System.out.println("T-two serial: " + Thread.currentThread().getName());
        }
    }

    public static void main(String[] args) {
        double result=(12+3*8)/4%3;
        System.out.println(result);
    }

    public static void q5() {
        int i = 10, j = 0;
        try {
            j += i / j;
            System.out.println(j);
        } catch (ArithmeticException exception) {
            System.out.println("ArithmeticException");
        } catch (Exception exception) {
            System.out.println("Exception");
        } finally {
            System.out.println(":" + j);
        }
    }

    public static void question1() {
        int x = 5;
        int y = x--;
        System.out.println(y);
        System.out.println(x);
        y += --x;
        System.out.println(y);
        System.out.println(x);
    }

    public static void question2() {
        int x = 3;
        switch (x) {
            case 2:
            case 3:
            case 4:
                ++x;
            default:
                x++;
        }
        System.out.println(x);
    }

    public static void question3() {
        for (int i = 0; ; ) {
            System.out.println(i);
            break;
        }
    }

    public static void question4() {
        int[] arr = {1, 2, 3, 4};
        int sum = 0;
        for (int i = 0; i < 4; i++) {
            switch (arr[i] % 2) {
                case 0:
                    sum += arr[i];
                    break;
                case 1:
                    sum -= arr[i];
                    break;
            }
        }
        System.out.println(sum);
    }

}
